package top.lixunda.commerce.common.core.controller.wrapper;

import com.sun.istack.internal.NotNull;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.List;

/**
 * @author LiXunda
 * @version time:2019/10/12 17:17
 */
@SuppressWarnings("ALL")
@Data
@Slf4j
public class ConditionSegment {

    private String op;

    private List<String> values;

    public ConditionSegment() {
    }

    public ConditionSegment(@NotNull String op, @NotNull List<String> values) {
        this(op, values == null ? new String[]{} : values.toArray(new String[]{}));
    }

    public ConditionSegment(String op, String... values) {
        if (op == null || "".equals(op)) {
            throw new IllegalArgumentException("op is not to be null");
        }
        if (values.length <= 0) {
            throw new IllegalArgumentException("not values");
        }
        this.op = op;
        this.values = Arrays.asList(values);
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder(op);
        if (values != null) {
            values.forEach(builder::append);
        }
        return builder.toString();
    }

}
